home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / graphic.zip / CIRCLE.C next >
Text File  |  1991-12-24  |  2KB  |  63 lines

  1. /**********************************************************************
  2. CIRCLE
  3. Description -circle(x coordinate, y coordinate, radius)
  4. **********************************************************************
  5. Function - draws a circle on the screen
  6. Input - integers for x,y center coordinates, integer for radius
  7. Output - to the screen
  8. #includes -
  9. #defines  - none
  10. Routines Called - plot8.c, plotxy.c
  11. Notes - listing 3 page 30 dec83 dobbs
  12. **********************************************************************/
  13. circle(xcenter,ycenter,radius)
  14. int xcenter,ycenter,radius;
  15. {
  16.   int xcrd,ycrd,a,b,f;
  17.   xcrd=radius;
  18.   ycrd=0;
  19.   a=-2*(xcrd+1);
  20.   b=1;
  21.   f=0;
  22.   do{
  23.      plot8(xcenter,ycenter,xcrd,ycrd);
  24.      ycrd=ycrd+1;
  25.      f=f+b;
  26.      if(f>radius){f=f+a;
  27.                   a=a+2;
  28.                   xcrd=xcrd-1;}
  29.      b=b+2;
  30.     }
  31.      while(b<=-a);
  32.   return;
  33. }
  34. /******************** end of function ********************************/
  35. /**********************************************************************
  36. PLOT8
  37. Description - plots 8 points for circle routine
  38. **********************************************************************
  39. Function -  plot8(xcenter,ycenter,xcrd,ycrd);
  40. Input - x,y coordinates of center pt, x,y coord of base octant
  41. Output - 8 characters to screen
  42. #includes - plotxy.c
  43. #defines  - none
  44. Routines Called - plotxy to print character
  45. Notes - no error checking, char is defined in plotxy
  46. **********************************************************************/
  47. plot8(xcenter,ycenter,xcrd,ycrd)
  48.  
  49. int xcenter,ycenter,xcrd,ycrd;
  50. {
  51.   plotxy(ycrd+xcenter,((2*xcrd)/5)+ycenter);    /* b quart c-clockwise   */
  52.   plotxy(-ycrd+xcenter,((2*xcrd)/5)+ycenter);   /* b quart clockwise */
  53.   plotxy(-ycrd+xcenter,((2*-xcrd)/5)+ycenter);  /* d quart c-clockwise   */
  54.   plotxy(ycrd+xcenter,((2*-xcrd)/5)+ycenter);   /* d quart clockwise */
  55.   plotxy(xcrd+xcenter,((2*-ycrd)/5)+ycenter);   /* a quart c-clockwise   */
  56.   plotxy(xcrd+xcenter,((2*ycrd)/5)+ycenter);    /* a quart clockwise */
  57.   plotxy(-xcrd+xcenter,((2*ycrd)/5)+ycenter);   /* c quart c-clockwise   */
  58.   plotxy(-xcrd+xcenter,((2*-ycrd)/5)+ycenter);  /* c quart clockwise */
  59.   return;
  60. }
  61.  
  62. /******************** end of function ********************************/
  63.